local shuangren = fk.CreateSkill{
    name = "hs__shuangren",
}

local H = require "packages.ol_hegemony.util"

shuangren:addEffect(fk.EventPhaseStart,{
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(shuangren.name) and player.phase == Player.Play and not player:isKongcheng() and table.find(player.room:getOtherPlayers(player, false), function(p)
          return not p:isKongcheng()
        end)
      end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local availableTargets = table.filter(room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
        if #availableTargets == 0 then return false end
        local to = room:askToChoosePlayers(player,{
            targets = availableTargets,
            min_num = 1,
            max_num = 1,
            prompt = "#hs_shuangren-ask",
            skill_name = shuangren.name,
            cancelable = true,
        })
        if #to > 0 then
          event:setCostData(self,{tos = to})
          return true
        end
        return false
      end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
        local pindian = player:pindian({to}, shuangren.name)
        if pindian.results[to].winner == player then
          if player.dead then return end
          local slash = Fk:cloneCard("slash")
          if player:prohibitUse(slash) then return false end
          local availableTargets = table.filter(room:getOtherPlayers(player, false), function(p) return H.compareKingdomWith(p, to) and not player:isProhibited(p, slash)
         end)
          if #availableTargets == 0 then return false end
          local victims = room:askToChoosePlayers(player,{
            targets = availableTargets,
            min_num = 1,
            max_num = 1,
            prompt = "#hs_shuangren_slash-ask:" .. target.id,
            skill_name = shuangren.name,
            cancelable = false,
        })
          if #victims > 0 then
            local tos = victims[1]
            if tos.dead then return false end
            room:useVirtualCard("slash", nil, player, {tos}, shuangren.name, true)
          end
        else
          room:setPlayerMark(player, "hs_shuangren-turn", 1)
        end
      end,
})

shuangren:addEffect("prohibit",{
  name = "#hs__shuangren_prohibit",
  is_prohibited = function(self, from, to, card)
    if from and from:hasSkill(shuangren.name) then
      return from:getMark("hs_shuangren-turn") > 0 and from ~= to
    end
  end,
})

Fk:loadTranslationTable{
    ["hs__shuangren"] = "双刃",
    [":hs__shuangren"] = "出牌阶段开始时，你可与一名其他角色进行拼点。若你赢，你视为对与其势力相同的一名角色使用【杀】；否则其他角色于此回合内不是你使用牌的合法目标。",

    ["#hs_shuangren-ask"] = "双刃：你可与一名角色拼点",
    ["#hs_shuangren_slash-ask"] = "双刃：你视为对与 %src 势力相同的一名角色使用【杀】",

    ["$hs__shuangren1"] = "仲国大将纪灵在此！",
    ["$hs__shuangren2"] = "吃我一记三尖两刃刀！",
}

return shuangren